2026-09-27 · class-notes, linux, linux-permissions, chmod, sudo, umask, chown
Full class notes for TLCL ch. 9: users/groups/other, read/write/execute, chmod, umask, special permissions, su/sudo, chown/chgrp, and passwd.
How these notes were made: the material supplied for this lesson was the chapter's own heading list — "Users, Groups, Members, and Everybody Else", "Reading, Writing, and Executing", "chmod", "umask", "Some Special Permissions", "Changing Identities" (su, sudo, chown, chgrp), "Executing Our Privileges", "Changing Your Password" — with an explicit instruction to draft the content from general knowledge rather than a transcript. These notes follow that structure, but the explanations are written from general knowledge of standard Linux/Unix permissions, not reproduced or paraphrased from William Shotts's actual book text, which was not supplied.
One heading is corrected below. The supplied list has "
chgrp— Set Default Permissions", butchgrpactually changes a file's group ownership — setting default permissions isumask's job, already covered earlier in the same list. This looks like a copy/paste slip in the source heading list rather than an intentional description, sochgrpis explained correctly below rather than under that mislabel. Worth checking against your own copy of the chapter either way.
Class notes · The Linux Command Line (3rd ed.), William Shotts · Chapter 9
Quick reference: the short version of this lesson lives in the The Linux Command Line resource sheets. This follows Chapter 8 (Advanced Keyboard Tricks) and moves from typing commands efficiently to one of the most important things those commands control: who is allowed to do what to a file.
By the end of these notes you should be able to:
chmod in both symbolic and octal (numeric) form.umask and how it sets default permissions.su from sudo, and use chown and chgrp correctly.passwd.Every file on a Linux system has an owner — the user account that created it (or was assigned ownership) — and belongs to a group. Linux permissions are built around three categories of "who":
Every one of a file's permissions is expressed separately for each of these three categories, which is why permission strings always come in sets of three.
For each of user/group/other, three permission bits can be set:
| Permission | On a file | On a directory |
|---|---|---|
| r (read) | View the file's contents | List the directory's contents |
| w (write) | Modify the file's contents | Create, delete or rename entries inside the directory |
| x (execute) | Run the file as a program/script | Enter (traverse into) the directory |
Exam tip: the directory meaning of each letter is a common trip-up. You can
lsa directory you can read but not execute (you'd see filenames but couldn'tcdinto it or access anything inside), and you cancdinto a directory you can execute but not read (you could access files by exact name, but not list what's there).
Running ls -l shows this as a ten-character string, for example:
-rwxr-xr-- 1 alice staff 1234 Jan 10 09:00 script.sh
Reading a permission string:
- rwx r-x r--
| | | |
| | | +-- other: read only
| | +------- group: read + execute
| +------------ user (owner): read + write + execute
+---------------- file type (- = regular file, d = directory)
chmod changes a file's permissions, in two notations.
Symbolic notation names who (u user, g group, o other, a all),
an operator (+ add, - remove, = set exactly), and what
(r, w, x):
chmod u+x script.sh # add execute for the owner
chmod g-w report.txt # remove write for the group
chmod o=r notes.txt # set "other" to read only, nothing else
chmod a+r public.txt # add read for everyone
Octal notation represents each category's permissions as a single digit, adding the values 4 (read), 2 (write), 1 (execute):
| Digit | Meaning |
|---|---|
| 7 | rwx (4+2+1) |
| 6 | rw- (4+2) |
| 5 | r-x (4+1) |
| 4 | r-- (4) |
| 0 | --- |
A full command gives three digits, one per user/group/other:
chmod 755 script.sh # rwxr-xr-x — owner full, group/other read+execute
chmod 644 notes.txt # rw-r--r-- — owner read/write, group/other read only
chmod 600 secret.key # rw------- — owner only, nothing for anyone else
Most desktop Linux file managers expose the same permission model through a
Properties dialog — typically a "Permissions" tab with checkboxes or
dropdowns for owner/group/other read/write/execute, doing exactly what
chmod does from the command line, just with a graphical interface.
New files and directories do not start out with every permission bit set — their starting permissions are governed by the umask (user file-creation mask). The umask is subtracted from a maximum starting point: 666 (rw-rw-rw-) for new files, and 777 (rwxrwxrwx) for new directories.
A common default umask is 022, which removes write permission for group and other:
File default: 666 (rw-rw-rw-)
umask: - 022
Result: 644 (rw-r--r--)
Directory default: 777 (rwxrwxrwx)
umask: - 022
Result: 755 (rwxr-xr-x)
You can view or set the current umask with the umask command:
umask
0022
umask 077 # a stricter default: only the owner gets any access
Beyond the standard read/write/execute bits, three special permission bits exist:
4000): on an executable, causes it to
run with the privileges of the file's owner, not the user who ran it.
Classic example: passwd is setuid root, so an ordinary user can update
the system's password database even though only root normally can.2000): on an executable, runs with the
privileges of the file's group. On a directory, causes new files
created inside it to inherit the directory's group automatically,
rather than the creating user's primary group.1000): on a directory, restricts deletion —
even if a user has write permission to the directory, they can only delete
or rename files they themselves own. The classic example is /tmp,
where everyone can create files, but nobody can delete someone else's.chmod u+s program # set setuid
chmod g+s shared_dir # set setgid on a directory
chmod +t /tmp # set the sticky bit
Note (beyond this lesson): an
ls -llisting shows these visually — setuid appears as ansin the owner's execute position, setgid as ansin the group's execute position, and the sticky bit as atin the other execute position (lowercase if the underlying execute bit is also set, uppercase if not).
su starts a new shell running as another user — commonly root, if run
with no username:
su # switch to root (prompts for root's password)
su alice # switch to the user "alice" (prompts for alice's password)
Once you exit that shell, you return to your original session.
sudo runs a single command with another user's privileges — again,
usually root — without starting a whole separate login session:
sudo apt update
sudo checks the invoking user's own password (not root's), and only
permits it if that user is listed (directly or via group membership) in the
system's sudoers configuration as authorised to run that command.
chown changes a file's owner, and optionally its group at the same
time:
chown alice file.txt # change owner to alice
chown alice:staff file.txt # change owner to alice, group to staff
chown :staff file.txt # change only the group, owner unchanged
chgrp changes only a file's group, without touching the owner:
chgrp staff file.txt
Correction: as noted at the top of these notes, the supplied heading list described
chgrpas setting default permissions — that isumask's function (Section 4).chgrp's actual job is changing a file's group ownership, which is what is explained here.
A team shares a directory that everyone in the devteam group should be able
to work in, with new files automatically belonging to that group.
sudo chgrp devteam /srv/project # set the directory's group
sudo chmod 2775 /srv/project # rwxrwsr-x: group write + setgid
The 2 in 2775 sets setgid on the directory, so every new file
created inside /srv/project automatically belongs to the devteam group,
regardless of which team member created it — saving everyone from having to
run chgrp manually on every new file.
Elevated access — via su, sudo, setuid programs, or simply being root —
comes with real responsibility, because those privileges bypass the normal
permission checks that protect a system from mistakes as well as attacks. A
command that would be safely blocked for an ordinary user can, run as root,
genuinely damage the system: deleting critical files, breaking package
databases, or misconfiguring something that other users and services depend
on.
The common-sense practice that follows is to use elevated privileges only
for the specific task that needs them, and to return to an ordinary,
unprivileged account as soon as that task is done — rather than working as
root generally "just in case." sudo's per-command model naturally
encourages this; a long-lived su root shell does not.
The passwd command changes a user's password:
passwd # change your own password
sudo passwd alice # (as root/via sudo) change another user's password
Run with no arguments, it prompts for your current password, then the
new one twice (to confirm it was typed correctly). This is the same
passwd program referenced in Section 5 as the classic example of a setuid
program — an ordinary user needs elevated privilege for a moment to update
the shared password database, and setuid is exactly the mechanism that grants
it, safely scoped to that one program.
Permissions are inherently a security topic, so the additions here focus on practical risk that the mechanics alone do not make obvious:
...66 or ...77) can be
modified by any user on the system — for a script that later runs with
elevated privilege, that is a direct path to privilege escalation for
anyone who can edit it first.sudo access is effectively root access, scoped only by configuration
discipline. A sudoers entry that allows a user to run a broad command,
or a command that can itself spawn a shell or edit arbitrary files (some
text editors, for instance), can be a route to full root even if the
literal command listed looks narrow. Scope sudo rules as tightly as the
task genuinely requires.sudo. The Section 7 point about using elevated access only as long as
needed is not just tidiness — every command typed in a root shell runs with
full privilege, including a mistyped or copy-pasted command that was meant
for a different context. sudo's command-at-a-time model reduces that
window.chown,
chgrp and passwd changes are exactly the kind of action that should be
logged and reviewable — an unexpected ownership change on a sensitive file,
or a password change the account holder did not request, are both classic
early indicators of compromise.chmod sets permissions symbolically (u+x, g-w, o=r) or in
octal (e.g. 755, 644), and GUIs expose the same model visually.umask sets the default permissions for new files/directories by
subtracting from 666/777 — a common default is 022 (giving 644/755)./tmp).su starts a shell as another user; sudo runs a single command as
another user (usually root), checked against the invoking user's own
password and the sudoers configuration.chown changes owner (and optionally group); chgrp changes group
only.passwd changes a password and is itself a classic setuid program.| Term | Meaning |
|---|---|
| Owner (user) | The account that owns a file. |
| Group | A set of accounts a file also grants permissions to. |
| Other | Everyone else on the system, beyond owner and group. |
| Permission string | The rwx-per-category display, e.g. rwxr-xr--. |
| chmod | Command to change a file's permissions. |
| Octal notation | Permissions as three digits (e.g. 755). |
| umask | The mask subtracted from default new-file permissions. |
| Setuid | Special bit: run an executable as its owner. |
| Setgid | Special bit: run as the file's group, or inherit group in a directory. |
| Sticky bit | Special bit: restrict directory deletion to the file's own owner. |
| su | Start a shell as another user. |
| sudo | Run one command as another user, per sudoers policy. |
| sudoers | The configuration defining who may use sudo, and for what. |
| chown | Command to change a file's owner (and optionally group). |
| chgrp | Command to change a file's group only. |
| passwd | Command to change a user's password. |
chmod g+x deploy.sh. Symbolic notation, adding execute for group.chmod g+s or the 2000 octal bit), so new
files inherit the directory's group automatically. Directory-level
setgid inheritance.